package net.csdn.business.mirror.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.csdn.business.common.domain.request.mirror.MirrorUserTokenDTO;
import net.csdn.business.mirror.entity.bean.UserGithubToken;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.ResultSetType;
import org.apache.ibatis.session.ResultHandler;
import org.springframework.stereotype.Repository;


@Repository
public interface UserGithubTokenMapper extends BaseMapper<UserGithubToken> {
    @Select("<script>" +
            "select * from user_github_token where user_id = #{userId} order by id desc limit 1" +
            "</script>")
    UserGithubToken latest(@Param("userId") String userId);


    /**
    * @Description: 新增或更新用户token
    * @Param:
    * @return:
    * @Author: zhangyl
    * @Date: 2024/7/18
    */
    @Insert("INSERT INTO user_github_token (username, user_id, third_username,data,status,type) VALUES (#{params.username}, #{params.userId}, #{params.thirdUsername}, #{params.token},1,#{params.type}) on duplicate key update data=#{params.token},status=1,third_username=#{params.thirdUsername} ")
    int addOrUpdate(@Param("params")MirrorUserTokenDTO params);



    /**
     * @Author zhangyl
     * @Description 流式加载数据，防止深分页问题
     * @Date 17:28 2024/2/27
     * @Param
     * @return
     **/
    @Options(resultSetType = ResultSetType.FORWARD_ONLY, fetchSize = Integer.MIN_VALUE)
    @ResultType(String.class)
    @Select("select id from user_github_token where status=1  ORDER BY id DESC")
    public void mybatisStreamQuery(ResultHandler<String> handler/*, @Param("eventsDay")String eventsDay*/);
}
